//
//  NewsCollectionViewCell.m
//  HYHOME
//
//  Created by cjy on 16/2/27.
//  Copyright © 2016年 Mac. All rights reserved.
//

#import "NewsCollectionViewCell.h"
#import "Model.h"
#import "UIImageView+WebCache.h"
#import "DKNightVersion.h"
@implementation NewsCollectionViewCell


-(void)dealloc{

    [self.cover_image_url release];
    [self.description1 release];
    [self.favorites_count release];
    [self.name release];
    [self.price release];
    [super dealloc];

}

-(instancetype)initWithFrame:(CGRect)frame{
    

    self = [super initWithFrame:frame];
    if (self) {
        
      
        [self createSubView];
        
     
        
    }
    return self;
}
- (void)createSubView{

    
    
    self.cover_image_url = [[UIImageView alloc]init];
    [self.contentView addSubview:self.cover_image_url];
    
    
    self.favorites_count  = [[UILabel alloc]init];
    [self.contentView addSubview:self.favorites_count];
    
    self.name  = [[UILabel alloc]init];
    [self.contentView addSubview:self.name];
    
    self.price  = [[UILabel alloc]init];
    [self.contentView addSubview:self.price];
    
    
    

    
//    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"ISNIGHT"]) {
//        
//        self.name.backgroundColor =[UIColor blackColor];
//        self.price.backgroundColor = [UIColor blackColor];
//        self.favorites_count.backgroundColor = [UIColor blackColor];
//
//        
//    }else {
//       
//        self.name.backgroundColor = [UIColor whiteColor];
//        self.price.backgroundColor = [UIColor whiteColor];
//        self.favorites_count.backgroundColor = [UIColor whiteColor];
//
//    }
    



    
 self.pic = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"iconfont-xihuan-2"]];
    [self.contentView addSubview:self.pic];
    [self.pic release];
    
    
    [self.cover_image_url release];
    [self.favorites_count release];
    [self.name release];
    [self.price release];



}
// collectionCell 的子控件布局通常在此方法中设置
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    
    self.cover_image_url.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.frame.size.height-75);
    
    self.name.frame = CGRectMake(0,self.frame.size.height-75, self.contentView.frame.size.width,40);
    
    self.name.textAlignment = NSTextAlignmentLeft;
    self.name.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor lightGrayColor]);
    self.favorites_count.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor lightGrayColor]);

    self.name.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
    self.favorites_count.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
    self.price.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);

    
    self.favorites_count.frame = CGRectMake(self.contentView.frame.size.width /2,self.frame.size.height-40, self.contentView.frame.size.width /2,20);
//    self.favorites_count.textAlignment = NSTextAlignmentRight;

    

    
    self.price.frame = CGRectMake(0,self.frame.size.height-40, self.contentView.frame.size.width/2,20);
//    self.price.textAlignment = NSTextAlignmentLeft;
    self.price.textColor = [UIColor redColor];
    
    self.pic.frame =CGRectMake(self.contentView.frame.size.width / 2 + 10,self.contentView.frame.size.height-40, 20,20);

    
}


-(UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    
    return layoutAttributes;
}



- (void)layoutSubviews{
    
    
    [super layoutSubviews];
    
}

-(void)passModel:(Model *)model{
    
    [self.cover_image_url sd_setImageWithURL:[NSURL URLWithString:model.cover_image_url]  placeholderImage:[UIImage imageNamed:@"jz"]];
    self.name.text = model.name;
    self.name.numberOfLines = 0;
    self.name.font = [UIFont boldSystemFontOfSize:13];
    self.name.text = [NSString stringWithFormat:@"  %@",model.name];

    
    self.favorites_count.text = [model.favorites_count stringValue];
    self.favorites_count.text = [NSString stringWithFormat:@"          %@",model.favorites_count];

    self.favorites_count.font = [UIFont systemFontOfSize:12];
    self.price.font = [UIFont systemFontOfSize:13];

    self.price.text = model.price ;
    self.price.text = [NSString stringWithFormat:@"  ¥ %@",model.price];
    
    self.price.textColor = [UIColor redColor];

    
    
}

@end
